
extern "C" {
    fn __ctype_b_loc() -> *mut *const u16;
    fn __errno_location() -> *mut i32;
    fn __ctype_get_mb_cur_max() -> size_t;
    fn free(_: *mut ());
    fn bsearch(
        __key: *const (),
        __base: *const (),
        __nmemb: size_t,
        __size: size_t,
        __compar: __compar_fn_t,
    ) -> *mut ();
    fn mbtowc(__pwc: *mut wchar_t, __s: *const i8, __n: size_t) -> i32;
    fn wctomb(__s: *mut i8, __wchar: wchar_t) -> i32;
    fn strlen(_: *const i8) -> u64;
    fn memcpy(_: *mut (), _: *const (), _: u64) -> *mut ();
    fn memcmp(_: *const (), _: *const (), _: u64) -> i32;
    fn memset(_: *mut (), _: i32, _: u64) -> *mut ();
    fn wcwidth(__c: wchar_t) -> i32;
    fn vis(_: *mut i8, _: i32, _: i32, _: i32) -> *mut i8;
    fn log_debug(_: *const i8, _: ...);
    fn fatalx(_: *const i8, _: ...) -> !;
    fn xmalloc(_: size_t) -> *mut ();
    fn xcalloc(_: size_t, _: size_t) -> *mut ();
    fn xrealloc(_: *mut (), _: size_t) -> *mut ();
    fn xstrdup(_: *const i8) -> *mut i8;
    fn xreallocarray(_: *mut (), _: size_t, _: size_t) -> *mut ();
}
pub type __u_char = u8;
pub type __u_int = u32;
pub type __ssize_t = i64;
pub type u_char = __u_char;
pub type u_int = __u_int;
pub type ssize_t = __ssize_t;
pub type size_t = u64;
pub type C2RustUnnamed = u32;
pub const _ISalnum: C2RustUnnamed = 8;
pub const _ISpunct: C2RustUnnamed = 4;
pub const _IScntrl: C2RustUnnamed = 2;
pub const _ISblank: C2RustUnnamed = 1;
pub const _ISgraph: C2RustUnnamed = 32768;
pub const _ISprint: C2RustUnnamed = 16384;
pub const _ISspace: C2RustUnnamed = 8192;
pub const _ISxdigit: C2RustUnnamed = 4096;
pub const _ISdigit: C2RustUnnamed = 2048;
pub const _ISalpha: C2RustUnnamed = 1024;
pub const _ISlower: C2RustUnnamed = 512;
pub const _ISupper: C2RustUnnamed = 256;
pub type wchar_t = i32;
pub type __compar_fn_t =
    Option<unsafe extern "C" fn(*const (), *const ()) -> i32>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data {
    pub data: [u_char; 21],
    pub have: u_char,
    pub size: u_char,
    pub width: u_char,
}
pub type utf8_char = u_int;
pub type utf8_state = u32;
pub const UTF8_ERROR: utf8_state = 2;
pub const UTF8_DONE: utf8_state = 1;
pub const UTF8_MORE: utf8_state = 0;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_item {
    pub index_entry: C2RustUnnamed_1,
    pub index: u_int,
    pub data_entry: C2RustUnnamed_0,
    pub data: [i8; 21],
    pub size: u_char,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_0 {
    pub rbe_left: *mut utf8_item,
    pub rbe_right: *mut utf8_item,
    pub rbe_parent: *mut utf8_item,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct C2RustUnnamed_1 {
    pub rbe_left: *mut utf8_item,
    pub rbe_right: *mut utf8_item,
    pub rbe_parent: *mut utf8_item,
    pub rbe_color: i32,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_data_tree {
    pub rbh_root: *mut utf8_item,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct utf8_index_tree {
    pub rbh_root: *mut utf8_item,
}
static mut utf8_force_wide: [wchar_t; 162] = [
    0x261d as i32,
    0x26f9 as i32,
    0x270a as i32,
    0x270b as i32,
    0x270c as i32,
    0x270d as i32,
    0x1f1e6 as i32,
    0x1f1e7 as i32,
    0x1f1e8 as i32,
    0x1f1e9 as i32,
    0x1f1ea as i32,
    0x1f1eb as i32,
    0x1f1ec as i32,
    0x1f1ed as i32,
    0x1f1ee as i32,
    0x1f1ef as i32,
    0x1f1f0 as i32,
    0x1f1f1 as i32,
    0x1f1f2 as i32,
    0x1f1f3 as i32,
    0x1f1f4 as i32,
    0x1f1f5 as i32,
    0x1f1f6 as i32,
    0x1f1f7 as i32,
    0x1f1f8 as i32,
    0x1f1f9 as i32,
    0x1f1fa as i32,
    0x1f1fb as i32,
    0x1f1fc as i32,
    0x1f1fd as i32,
    0x1f1fe as i32,
    0x1f1ff as i32,
    0x1f385 as i32,
    0x1f3c2 as i32,
    0x1f3c3 as i32,
    0x1f3c4 as i32,
    0x1f3c7 as i32,
    0x1f3ca as i32,
    0x1f3cb as i32,
    0x1f3cc as i32,
    0x1f3fb as i32,
    0x1f3fc as i32,
    0x1f3fd as i32,
    0x1f3fe as i32,
    0x1f3ff as i32,
    0x1f442 as i32,
    0x1f443 as i32,
    0x1f446 as i32,
    0x1f447 as i32,
    0x1f448 as i32,
    0x1f449 as i32,
    0x1f44a as i32,
    0x1f44b as i32,
    0x1f44c as i32,
    0x1f44d as i32,
    0x1f44e as i32,
    0x1f44f as i32,
    0x1f450 as i32,
    0x1f466 as i32,
    0x1f467 as i32,
    0x1f468 as i32,
    0x1f469 as i32,
    0x1f46b as i32,
    0x1f46c as i32,
    0x1f46d as i32,
    0x1f46e as i32,
    0x1f470 as i32,
    0x1f471 as i32,
    0x1f472 as i32,
    0x1f473 as i32,
    0x1f474 as i32,
    0x1f475 as i32,
    0x1f476 as i32,
    0x1f477 as i32,
    0x1f478 as i32,
    0x1f47c as i32,
    0x1f481 as i32,
    0x1f482 as i32,
    0x1f483 as i32,
    0x1f485 as i32,
    0x1f486 as i32,
    0x1f487 as i32,
    0x1f48f as i32,
    0x1f491 as i32,
    0x1f4aa as i32,
    0x1f574 as i32,
    0x1f575 as i32,
    0x1f57a as i32,
    0x1f590 as i32,
    0x1f595 as i32,
    0x1f596 as i32,
    0x1f645 as i32,
    0x1f646 as i32,
    0x1f647 as i32,
    0x1f64b as i32,
    0x1f64c as i32,
    0x1f64d as i32,
    0x1f64e as i32,
    0x1f64f as i32,
    0x1f6a3 as i32,
    0x1f6b4 as i32,
    0x1f6b5 as i32,
    0x1f6b6 as i32,
    0x1f6c0 as i32,
    0x1f6cc as i32,
    0x1f90c as i32,
    0x1f90f as i32,
    0x1f918 as i32,
    0x1f919 as i32,
    0x1f91a as i32,
    0x1f91b as i32,
    0x1f91c as i32,
    0x1f91d as i32,
    0x1f91e as i32,
    0x1f91f as i32,
    0x1f926 as i32,
    0x1f930 as i32,
    0x1f931 as i32,
    0x1f932 as i32,
    0x1f933 as i32,
    0x1f934 as i32,
    0x1f935 as i32,
    0x1f936 as i32,
    0x1f937 as i32,
    0x1f938 as i32,
    0x1f939 as i32,
    0x1f93d as i32,
    0x1f93e as i32,
    0x1f977 as i32,
    0x1f9b5 as i32,
    0x1f9b6 as i32,
    0x1f9b8 as i32,
    0x1f9b9 as i32,
    0x1f9bb as i32,
    0x1f9cd as i32,
    0x1f9ce as i32,
    0x1f9cf as i32,
    0x1f9d1 as i32,
    0x1f9d2 as i32,
    0x1f9d3 as i32,
    0x1f9d4 as i32,
    0x1f9d5 as i32,
    0x1f9d6 as i32,
    0x1f9d7 as i32,
    0x1f9d8 as i32,
    0x1f9d9 as i32,
    0x1f9da as i32,
    0x1f9db as i32,
    0x1f9dc as i32,
    0x1f9dd as i32,
    0x1fac3 as i32,
    0x1fac4 as i32,
    0x1fac5 as i32,
    0x1faf0 as i32,
    0x1faf1 as i32,
    0x1faf2 as i32,
    0x1faf3 as i32,
    0x1faf4 as i32,
    0x1faf5 as i32,
    0x1faf6 as i32,
    0x1faf7 as i32,
    0x1faf8 as i32,
];
extern "C" fn utf8_data_cmp(mut ui1: *mut utf8_item, mut ui2: *mut utf8_item) -> i32 {
    if ((unsafe { (*ui1).size }) as i32) < (unsafe { (*ui2).size }) as i32 {
        return -(1 as i32);
    }
    if (unsafe { (*ui1).size }) as i32 > (unsafe { (*ui2).size }) as i32 {
        return 1;
    }
    return unsafe {
        memcmp(
            ((*ui1).data).as_mut_ptr() as *const (),
            ((*ui2).data).as_mut_ptr() as *const (),
            (*ui1).size as u64,
        )
    };
}
extern "C" fn utf8_data_tree_RB_INSERT_COLOR(
    mut head: *mut utf8_data_tree,
    mut elm: *mut utf8_item,
) {
    let mut parent: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut gparent: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut tmp: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    loop {
        parent = unsafe { (*elm).data_entry.rbe_parent };
        if parent.is_null() || (unsafe { (*parent).data_entry.rbe_color }) != 1 {
            break;
        }
        gparent = unsafe { (*parent).data_entry.rbe_parent };
        if parent == (unsafe { (*gparent).data_entry.rbe_left }) {
            tmp = unsafe { (*gparent).data_entry.rbe_right };
            if !tmp.is_null() && (unsafe { (*tmp).data_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).data_entry.rbe_color = 0 });
                (unsafe { (*parent).data_entry.rbe_color = 0 });
                (unsafe { (*gparent).data_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).data_entry.rbe_right }) == elm {
                    tmp = unsafe { (*parent).data_entry.rbe_right };
                    (unsafe { (*parent).data_entry.rbe_right = (*tmp).data_entry.rbe_left });
                    if !(unsafe { (*parent).data_entry.rbe_right }).is_null() {
                        (unsafe { (*(*tmp).data_entry.rbe_left).data_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).data_entry.rbe_parent = (*parent).data_entry.rbe_parent });
                    if !(unsafe { (*tmp).data_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).data_entry.rbe_parent).data_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).data_entry.rbe_parent).data_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).data_entry.rbe_parent).data_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).data_entry.rbe_left = parent });
                    (unsafe { (*parent).data_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).data_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).data_entry.rbe_color = 0 });
                (unsafe { (*gparent).data_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).data_entry.rbe_left };
                (unsafe { (*gparent).data_entry.rbe_left = (*tmp).data_entry.rbe_right });
                if !(unsafe { (*gparent).data_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).data_entry.rbe_right).data_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).data_entry.rbe_parent = (*gparent).data_entry.rbe_parent });
                if !(unsafe { (*tmp).data_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).data_entry.rbe_parent).data_entry.rbe_left })
                    {
                        (unsafe { (*(*gparent).data_entry.rbe_parent).data_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).data_entry.rbe_parent).data_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).data_entry.rbe_right = gparent });
                (unsafe { (*gparent).data_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).data_entry.rbe_parent }).is_null();
            }
        } else {
            tmp = unsafe { (*gparent).data_entry.rbe_left };
            if !tmp.is_null() && (unsafe { (*tmp).data_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).data_entry.rbe_color = 0 });
                (unsafe { (*parent).data_entry.rbe_color = 0 });
                (unsafe { (*gparent).data_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).data_entry.rbe_left }) == elm {
                    tmp = unsafe { (*parent).data_entry.rbe_left };
                    (unsafe { (*parent).data_entry.rbe_left = (*tmp).data_entry.rbe_right });
                    if !(unsafe { (*parent).data_entry.rbe_left }).is_null() {
                        (unsafe { (*(*tmp).data_entry.rbe_right).data_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).data_entry.rbe_parent = (*parent).data_entry.rbe_parent });
                    if !(unsafe { (*tmp).data_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).data_entry.rbe_parent).data_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).data_entry.rbe_parent).data_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).data_entry.rbe_parent).data_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).data_entry.rbe_right = parent });
                    (unsafe { (*parent).data_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).data_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).data_entry.rbe_color = 0 });
                (unsafe { (*gparent).data_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).data_entry.rbe_right };
                (unsafe { (*gparent).data_entry.rbe_right = (*tmp).data_entry.rbe_left });
                if !(unsafe { (*gparent).data_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).data_entry.rbe_left).data_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).data_entry.rbe_parent = (*gparent).data_entry.rbe_parent });
                if !(unsafe { (*tmp).data_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).data_entry.rbe_parent).data_entry.rbe_left })
                    {
                        (unsafe { (*(*gparent).data_entry.rbe_parent).data_entry.rbe_left = tmp });
                    } else {
                        (unsafe { (*(*gparent).data_entry.rbe_parent).data_entry.rbe_right = tmp });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).data_entry.rbe_left = gparent });
                (unsafe { (*gparent).data_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).data_entry.rbe_parent }).is_null();
            }
        }
    }
    (unsafe { (*(*head).rbh_root).data_entry.rbe_color = 0 });
}
extern "C" fn utf8_data_tree_RB_FIND(
    mut head: *mut utf8_data_tree,
    mut elm: *mut utf8_item,
) -> *mut utf8_item {
    let mut tmp: *mut utf8_item = unsafe { (*head).rbh_root };
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = utf8_data_cmp(elm, tmp);
        if comp < 0 {
            tmp = unsafe { (*tmp).data_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).data_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<utf8_item>();
}
extern "C" fn utf8_data_tree_RB_INSERT(
    mut head: *mut utf8_data_tree,
    mut elm: *mut utf8_item,
) -> *mut utf8_item {
    let mut tmp: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut parent: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut comp: i32 = 0;
    tmp = unsafe { (*head).rbh_root };
    while !tmp.is_null() {
        parent = tmp;
        comp = utf8_data_cmp(elm, parent);
        if comp < 0 {
            tmp = unsafe { (*tmp).data_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).data_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    (unsafe { (*elm).data_entry.rbe_parent = parent });
    (unsafe { (*elm).data_entry.rbe_right = std::ptr::null_mut::<utf8_item>() });
    (unsafe { (*elm).data_entry.rbe_left = (*elm).data_entry.rbe_right });
    (unsafe { (*elm).data_entry.rbe_color = 1 });
    if !parent.is_null() {
        if comp < 0 {
            (unsafe { (*parent).data_entry.rbe_left = elm });
        } else {
            (unsafe { (*parent).data_entry.rbe_right = elm });
        }
    } else {
        (unsafe { (*head).rbh_root = elm });
    }
    utf8_data_tree_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<utf8_item>();
}
static mut utf8_data_tree: utf8_data_tree = {
    let mut init = utf8_data_tree {
        rbh_root: 0 as *const utf8_item as *mut utf8_item,
    };
    init
};
extern "C" fn utf8_index_cmp(mut ui1: *mut utf8_item, mut ui2: *mut utf8_item) -> i32 {
    if (unsafe { (*ui1).index }) < (unsafe { (*ui2).index }) {
        return -(1 as i32);
    }
    if (unsafe { (*ui1).index }) > (unsafe { (*ui2).index }) {
        return 1;
    }
    return 0;
}
extern "C" fn utf8_index_tree_RB_FIND(
    mut head: *mut utf8_index_tree,
    mut elm: *mut utf8_item,
) -> *mut utf8_item {
    let mut tmp: *mut utf8_item = unsafe { (*head).rbh_root };
    let mut comp: i32 = 0;
    while !tmp.is_null() {
        comp = utf8_index_cmp(elm, tmp);
        if comp < 0 {
            tmp = unsafe { (*tmp).index_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).index_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    return std::ptr::null_mut::<utf8_item>();
}
extern "C" fn utf8_index_tree_RB_INSERT(
    mut head: *mut utf8_index_tree,
    mut elm: *mut utf8_item,
) -> *mut utf8_item {
    let mut tmp: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut parent: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut comp: i32 = 0;
    tmp = unsafe { (*head).rbh_root };
    while !tmp.is_null() {
        parent = tmp;
        comp = utf8_index_cmp(elm, parent);
        if comp < 0 {
            tmp = unsafe { (*tmp).index_entry.rbe_left };
        } else if comp > 0 {
            tmp = unsafe { (*tmp).index_entry.rbe_right };
        } else {
            return tmp;
        }
    }
    (unsafe { (*elm).index_entry.rbe_parent = parent });
    (unsafe { (*elm).index_entry.rbe_right = std::ptr::null_mut::<utf8_item>() });
    (unsafe { (*elm).index_entry.rbe_left = (*elm).index_entry.rbe_right });
    (unsafe { (*elm).index_entry.rbe_color = 1 });
    if !parent.is_null() {
        if comp < 0 {
            (unsafe { (*parent).index_entry.rbe_left = elm });
        } else {
            (unsafe { (*parent).index_entry.rbe_right = elm });
        }
    } else {
        (unsafe { (*head).rbh_root = elm });
    }
    utf8_index_tree_RB_INSERT_COLOR(head, elm);
    return std::ptr::null_mut::<utf8_item>();
}
extern "C" fn utf8_index_tree_RB_INSERT_COLOR(
    mut head: *mut utf8_index_tree,
    mut elm: *mut utf8_item,
) {
    let mut parent: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut gparent: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut tmp: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    loop {
        parent = unsafe { (*elm).index_entry.rbe_parent };
        if parent.is_null() || (unsafe { (*parent).index_entry.rbe_color }) != 1 {
            break;
        }
        gparent = unsafe { (*parent).index_entry.rbe_parent };
        if parent == (unsafe { (*gparent).index_entry.rbe_left }) {
            tmp = unsafe { (*gparent).index_entry.rbe_right };
            if !tmp.is_null() && (unsafe { (*tmp).index_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).index_entry.rbe_color = 0 });
                (unsafe { (*parent).index_entry.rbe_color = 0 });
                (unsafe { (*gparent).index_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).index_entry.rbe_right }) == elm {
                    tmp = unsafe { (*parent).index_entry.rbe_right };
                    (unsafe { (*parent).index_entry.rbe_right = (*tmp).index_entry.rbe_left });
                    if !(unsafe { (*parent).index_entry.rbe_right }).is_null() {
                        (unsafe { (*(*tmp).index_entry.rbe_left).index_entry.rbe_parent = parent });
                    }
                    (unsafe { (*tmp).index_entry.rbe_parent = (*parent).index_entry.rbe_parent });
                    if !(unsafe { (*tmp).index_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).index_entry.rbe_parent).index_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).index_entry.rbe_parent).index_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).index_entry.rbe_parent).index_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).index_entry.rbe_left = parent });
                    (unsafe { (*parent).index_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).index_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).index_entry.rbe_color = 0 });
                (unsafe { (*gparent).index_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).index_entry.rbe_left };
                (unsafe { (*gparent).index_entry.rbe_left = (*tmp).index_entry.rbe_right });
                if !(unsafe { (*gparent).index_entry.rbe_left }).is_null() {
                    (unsafe { (*(*tmp).index_entry.rbe_right).index_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).index_entry.rbe_parent = (*gparent).index_entry.rbe_parent });
                if !(unsafe { (*tmp).index_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).index_entry.rbe_parent).index_entry.rbe_left })
                    {
                        (unsafe {
                            (*(*gparent).index_entry.rbe_parent).index_entry.rbe_left = tmp
                        });
                    } else {
                        (unsafe {
                            (*(*gparent).index_entry.rbe_parent).index_entry.rbe_right = tmp
                        });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).index_entry.rbe_right = gparent });
                (unsafe { (*gparent).index_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).index_entry.rbe_parent }).is_null();
            }
        } else {
            tmp = unsafe { (*gparent).index_entry.rbe_left };
            if !tmp.is_null() && (unsafe { (*tmp).index_entry.rbe_color }) == 1 {
                (unsafe { (*tmp).index_entry.rbe_color = 0 });
                (unsafe { (*parent).index_entry.rbe_color = 0 });
                (unsafe { (*gparent).index_entry.rbe_color = 1 });
                elm = gparent;
            } else {
                if (unsafe { (*parent).index_entry.rbe_left }) == elm {
                    tmp = unsafe { (*parent).index_entry.rbe_left };
                    (unsafe { (*parent).index_entry.rbe_left = (*tmp).index_entry.rbe_right });
                    if !(unsafe { (*parent).index_entry.rbe_left }).is_null() {
                        (unsafe {
                            (*(*tmp).index_entry.rbe_right).index_entry.rbe_parent = parent
                        });
                    }
                    (unsafe { (*tmp).index_entry.rbe_parent = (*parent).index_entry.rbe_parent });
                    if !(unsafe { (*tmp).index_entry.rbe_parent }).is_null() {
                        if parent
                            == (unsafe { (*(*parent).index_entry.rbe_parent).index_entry.rbe_left })
                        {
                            (unsafe {
                                (*(*parent).index_entry.rbe_parent).index_entry.rbe_left = tmp
                            });
                        } else {
                            (unsafe {
                                (*(*parent).index_entry.rbe_parent).index_entry.rbe_right = tmp
                            });
                        }
                    } else {
                        (unsafe { (*head).rbh_root = tmp });
                    }
                    (unsafe { (*tmp).index_entry.rbe_right = parent });
                    (unsafe { (*parent).index_entry.rbe_parent = tmp });
                    let _ = !(unsafe { (*tmp).index_entry.rbe_parent }).is_null();
                    tmp = parent;
                    parent = elm;
                    elm = tmp;
                }
                (unsafe { (*parent).index_entry.rbe_color = 0 });
                (unsafe { (*gparent).index_entry.rbe_color = 1 });
                tmp = unsafe { (*gparent).index_entry.rbe_right };
                (unsafe { (*gparent).index_entry.rbe_right = (*tmp).index_entry.rbe_left });
                if !(unsafe { (*gparent).index_entry.rbe_right }).is_null() {
                    (unsafe { (*(*tmp).index_entry.rbe_left).index_entry.rbe_parent = gparent });
                }
                (unsafe { (*tmp).index_entry.rbe_parent = (*gparent).index_entry.rbe_parent });
                if !(unsafe { (*tmp).index_entry.rbe_parent }).is_null() {
                    if gparent
                        == (unsafe { (*(*gparent).index_entry.rbe_parent).index_entry.rbe_left })
                    {
                        (unsafe {
                            (*(*gparent).index_entry.rbe_parent).index_entry.rbe_left = tmp
                        });
                    } else {
                        (unsafe {
                            (*(*gparent).index_entry.rbe_parent).index_entry.rbe_right = tmp
                        });
                    }
                } else {
                    (unsafe { (*head).rbh_root = tmp });
                }
                (unsafe { (*tmp).index_entry.rbe_left = gparent });
                (unsafe { (*gparent).index_entry.rbe_parent = tmp });
                let _ = !(unsafe { (*tmp).index_entry.rbe_parent }).is_null();
            }
        }
    }
    (unsafe { (*(*head).rbh_root).index_entry.rbe_color = 0 });
}
static mut utf8_index_tree: utf8_index_tree = {
    let mut init = utf8_index_tree {
        rbh_root: 0 as *const utf8_item as *mut utf8_item,
    };
    init
};
static mut utf8_next_index: u_int = 0;
extern "C" fn utf8_item_by_data(mut data: *const u_char, mut size: size_t) -> *mut utf8_item {
    let mut ui: utf8_item = utf8_item {
        index_entry: C2RustUnnamed_1 {
            rbe_left: std::ptr::null_mut::<utf8_item>(),
            rbe_right: std::ptr::null_mut::<utf8_item>(),
            rbe_parent: std::ptr::null_mut::<utf8_item>(),
            rbe_color: 0,
        },
        index: 0,
        data_entry: C2RustUnnamed_0 {
            rbe_left: std::ptr::null_mut::<utf8_item>(),
            rbe_right: std::ptr::null_mut::<utf8_item>(),
            rbe_parent: std::ptr::null_mut::<utf8_item>(),
            rbe_color: 0,
        },
        data: [0; 21],
        size: 0,
    };
    (unsafe {
        memcpy(
            (ui.data).as_mut_ptr() as *mut (),
            data as *const (),
            size,
        )
    });
    ui.size = size as u_char;
    return utf8_data_tree_RB_FIND(unsafe { &mut utf8_data_tree }, &mut ui);
}
extern "C" fn utf8_item_by_index(mut index: u_int) -> *mut utf8_item {
    let mut ui: utf8_item = utf8_item {
        index_entry: C2RustUnnamed_1 {
            rbe_left: std::ptr::null_mut::<utf8_item>(),
            rbe_right: std::ptr::null_mut::<utf8_item>(),
            rbe_parent: std::ptr::null_mut::<utf8_item>(),
            rbe_color: 0,
        },
        index: 0,
        data_entry: C2RustUnnamed_0 {
            rbe_left: std::ptr::null_mut::<utf8_item>(),
            rbe_right: std::ptr::null_mut::<utf8_item>(),
            rbe_parent: std::ptr::null_mut::<utf8_item>(),
            rbe_color: 0,
        },
        data: [0; 21],
        size: 0,
    };
    ui.index = index;
    return utf8_index_tree_RB_FIND(unsafe { &mut utf8_index_tree }, &mut ui);
}
extern "C" fn utf8_put_item(
    mut data: *const u_char,
    mut size: size_t,
    mut index: *mut u_int,
) -> i32 {
    let mut ui: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    ui = utf8_item_by_data(data, size);
    if !ui.is_null() {
        (unsafe { *index = (*ui).index });
        (unsafe {
            log_debug(
                b"%s: found %.*s = %u\0" as *const u8 as *const i8,
                (*::core::mem::transmute::<&[u8; 14], &[i8; 14]>(b"utf8_put_item\0")).as_ptr(),
                size as i32,
                data,
                *index,
            )
        });
        return 0;
    }
    if (unsafe { utf8_next_index }) == (0xffffff as i32 + 1) as u32 {
        return -(1 as i32);
    }
    ui = (unsafe {
        xcalloc( 1 as size_t,
            ::core::mem::size_of::<utf8_item>() as u64,
        )
    }) as *mut utf8_item;
    let fresh0 = unsafe { utf8_next_index };
    (unsafe { utf8_next_index = utf8_next_index.wrapping_add(1) });
    (unsafe { (*ui).index = fresh0 });
    utf8_index_tree_RB_INSERT(unsafe { &mut utf8_index_tree }, ui);
    (unsafe {
        memcpy(
            ((*ui).data).as_mut_ptr() as *mut (),
            data as *const (),
            size,
        )
    });
    (unsafe { (*ui).size = size as u_char });
    utf8_data_tree_RB_INSERT(unsafe { &mut utf8_data_tree }, ui);
    (unsafe { *index = (*ui).index });
    (unsafe {
        log_debug(
            b"%s: added %.*s = %u\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 14], &[i8; 14]>(b"utf8_put_item\0")).as_ptr(),
            size as i32,
            data,
            *index,
        )
    });
    return 0;
}
extern "C" fn utf8_table_cmp(mut vp1: *const (), mut vp2: *const ()) -> i32 {
    let mut wc1: *const wchar_t = vp1 as *const wchar_t;
    let mut wc2: *const wchar_t = vp2 as *const wchar_t;
    if (unsafe { *wc1 }) < (unsafe { *wc2 }) {
        return -(1 as i32);
    }
    if (unsafe { *wc1 }) > (unsafe { *wc2 }) {
        return 1;
    }
    return 0;
}
#[no_mangle]
pub extern "C" fn utf8_in_table(
    mut find: wchar_t,
    mut table: *const wchar_t,
    mut count: u_int,
) -> i32 {
    let mut found: *mut wchar_t = std::ptr::null_mut::<wchar_t>();
    found = (unsafe {
        bsearch(
            &mut find as *mut wchar_t as *const (),
            table as *const (),
            count as size_t,
            ::core::mem::size_of::<wchar_t>() as u64,
            Some(
                utf8_table_cmp
                    as unsafe extern "C" fn(*const (), *const ()) -> i32,
            ),
        )
    }) as *mut wchar_t;
    return (found != std::ptr::null_mut::<()>() as *mut wchar_t) as i32;
}
#[no_mangle]
pub extern "C" fn utf8_from_data(mut ud: *const utf8_data, mut uc: *mut utf8_char) -> utf8_state {
    let mut current_block: u64;
    let mut index: u_int = 0;
    if (unsafe { (*ud).width }) as i32 > 2 {
        (unsafe {
            fatalx(
                b"invalid UTF-8 width: %u\0" as *const u8 as *const i8,
                (*ud).width as i32,
            )
        });
    }
    if (unsafe { (*ud).size }) as i32 <= 21 {
        if (unsafe { (*ud).size }) as i32 <= 3 {
            index = ((unsafe { (*ud).data[2 as i32 as usize] }) as utf8_char) << 16
                | ((unsafe { (*ud).data[1 as i32 as usize] }) as utf8_char) << 8
                | (unsafe { (*ud).data[0 as i32 as usize] }) as utf8_char;
            current_block = 11875828834189669668;
        } else if utf8_put_item(
            unsafe { ((*ud).data).as_ptr() },
            (unsafe { (*ud).size }) as size_t,
            &mut index,
        ) != 0
        {
            current_block = 15722422845613226328;
        } else {
            current_block = 11875828834189669668;
        }
        match current_block {
            15722422845613226328 => {}
            _ => {
                (unsafe {
                    *uc = ((*ud).size as utf8_char) << 24
                        | ((*ud).width as utf8_char).wrapping_add(1 as i32 as u32) << 29
                        | index
                });
                (unsafe {
                    log_debug(
                        b"%s: (%d %d %.*s) -> %08x\0" as *const u8 as *const i8,
                        (*::core::mem::transmute::<&[u8; 15], &[i8; 15]>(b"utf8_from_data\0"))
                            .as_ptr(),
                        (*ud).width as i32,
                        (*ud).size as i32,
                        (*ud).size as i32,
                        ((*ud).data).as_ptr(),
                        *uc,
                    )
                });
                return UTF8_DONE;
            }
        }
    }
    if (unsafe { (*ud).width }) as i32 == 0 {
        (unsafe {
            *uc = (0 as i32 as utf8_char) << 24
                | (0 as i32 as utf8_char).wrapping_add(1 as i32 as u32) << 29
        });
    } else if (unsafe { (*ud).width }) as i32 == 1 {
        (unsafe {
            *uc = (1 as i32 as utf8_char) << 24
                | (1 as i32 as utf8_char).wrapping_add(1 as i32 as u32) << 29
                | 0x20 as i32 as u32
        });
    } else {
        (unsafe {
            *uc = (1 as i32 as utf8_char) << 24
                | (1 as i32 as utf8_char).wrapping_add(1 as i32 as u32) << 29
                | 0x2020 as i32 as u32
        });
    }
    return UTF8_ERROR;
}
#[no_mangle]
pub extern "C" fn utf8_to_data(mut uc: utf8_char, mut ud: *mut utf8_data) {
    let mut ui: *mut utf8_item = std::ptr::null_mut::<utf8_item>();
    let mut index: u_int = 0;
    (unsafe {
        memset(
            ud as *mut (), 0,
            ::core::mem::size_of::<utf8_data>() as u64,
        )
    });
    (unsafe { (*ud).have = (uc >> 24 & 0x1f as i32 as u32) as u_char });
    (unsafe { (*ud).size = (*ud).have });
    (unsafe { (*ud).width = (uc >> 29).wrapping_sub(1 as i32 as u32) as u_char });
    if (unsafe { (*ud).size }) as i32 <= 3 {
        (unsafe { (*ud).data[2 as i32 as usize] = (uc >> 16) as u_char });
        (unsafe {
            (*ud).data[1 as i32 as usize] = (uc >> 8 & 0xff as i32 as u32) as u_char
        });
        (unsafe { (*ud).data[0 as i32 as usize] = (uc & 0xff as i32 as u32) as u_char });
    } else {
        index = uc & 0xffffff as i32 as u32;
        ui = utf8_item_by_index(index);
        if ui.is_null() {
            (unsafe {
                memset(
                    ((*ud).data).as_mut_ptr() as *mut (),
                    ' ' as i32,
                    (*ud).size as u64,
                )
            });
        } else {
            (unsafe {
                memcpy(
                    ((*ud).data).as_mut_ptr() as *mut (),
                    ((*ui).data).as_mut_ptr() as *const (),
                    (*ud).size as u64,
                )
            });
        }
    }
    (unsafe {
        log_debug(
            b"%s: %08x -> (%d %d %.*s)\0" as *const u8 as *const i8,
            (*::core::mem::transmute::<&[u8; 13], &[i8; 13]>(b"utf8_to_data\0")).as_ptr(),
            uc,
            (*ud).width as i32,
            (*ud).size as i32,
            (*ud).size as i32,
            ((*ud).data).as_mut_ptr(),
        )
    });
}
#[no_mangle]
pub extern "C" fn utf8_build_one(mut ch: u_char) -> utf8_char {
    return (1 as i32 as utf8_char) << 24
        | (1 as i32 as utf8_char).wrapping_add(1 as i32 as u32) << 29
        | ch as u32;
}
#[no_mangle]
pub extern "C" fn utf8_set(mut ud: *mut utf8_data, mut ch: u_char) {
    static mut empty: utf8_data = {
        let mut init = utf8_data {
            data: [ 0 as u_char,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
                0,
            ],
            have: 1 as u_char,
            size: 1 as u_char,
            width: 1 as u_char,
        };
        init
    };
    (unsafe {
        memcpy(
            ud as *mut (),
            &empty as *const utf8_data as *const (),
            ::core::mem::size_of::<utf8_data>() as u64,
        )
    });
    (unsafe { *((*ud).data).as_mut_ptr() = ch });
}
#[no_mangle]
pub extern "C" fn utf8_copy(mut to: *mut utf8_data, mut from: *const utf8_data) {
    let mut i: u_int = 0;
    (unsafe {
        memcpy(
            to as *mut (),
            from as *const (),
            ::core::mem::size_of::<utf8_data>() as u64,
        )
    });
    i = (unsafe { (*to).size }) as u_int;
    while (i as u64) < ::core::mem::size_of::<[u_char; 21]>() as u64 {
        (unsafe { (*to).data[i as usize] = '\0' as i32 as u_char });
        i = i.wrapping_add(1);
    }
}
extern "C" fn utf8_width(mut ud: *mut utf8_data, mut width: *mut i32) -> utf8_state {
    let mut wc: wchar_t = 0;
    if utf8_towc(ud, &mut wc) as u32 != UTF8_DONE as i32 as u32 {
        return UTF8_ERROR;
    }
    if utf8_in_table(
        wc,
        unsafe { utf8_force_wide.as_ptr() },
        (::core::mem::size_of::<[wchar_t; 162]>() as u64)
            .wrapping_div(::core::mem::size_of::<wchar_t>() as u64) as u_int,
    ) != 0
    {
        (unsafe { *width = 2 });
        return UTF8_DONE;
    }
    (unsafe { *width = wcwidth(wc) });
    (unsafe {
        log_debug(
            b"wcwidth(%05X) returned %d\0" as *const u8 as *const i8,
            wc as u_int,
            *width,
        )
    });
    if (unsafe { *width }) < 0 {
        (unsafe {
            *width = if wc >= 0x80 as i32 && wc <= 0x9f as i32 { 0
            } else { 1
            }
        });
    }
    if (unsafe { *width }) >= 0 && (unsafe { *width }) <= 0xff as i32 {
        return UTF8_DONE;
    }
    return UTF8_ERROR;
}
#[no_mangle]
pub extern "C" fn utf8_towc(mut ud: *const utf8_data, mut wc: *mut wchar_t) -> utf8_state {
    match unsafe { mbtowc(wc, ((*ud).data).as_ptr() as *const i8, (*ud).size as size_t) } {
        -1 => {
            (unsafe {
                log_debug(
                    b"UTF-8 %.*s, mbtowc() %d\0" as *const u8 as *const i8,
                    (*ud).size as i32,
                    ((*ud).data).as_ptr(),
                    *__errno_location(),
                )
            });
            (unsafe {
                mbtowc(
                    std::ptr::null_mut::<wchar_t>(),
                    std::ptr::null::<i8>(),
                    __ctype_get_mb_cur_max(),
                )
            });
            return UTF8_ERROR;
        }
        0 => return UTF8_ERROR,
        _ => {}
    }
    (unsafe {
        log_debug(
            b"UTF-8 %.*s is %05X\0" as *const u8 as *const i8,
            (*ud).size as i32,
            ((*ud).data).as_ptr(),
            *wc as u_int,
        )
    });
    return UTF8_DONE;
}
#[no_mangle]
pub extern "C" fn utf8_fromwc(mut wc: wchar_t, mut ud: *mut utf8_data) -> utf8_state {
    let mut size: i32 = 0;
    let mut width: i32 = 0;
    size = unsafe { wctomb(((*ud).data).as_mut_ptr() as *mut i8, wc) };
    if size < 0 {
        (unsafe {
            log_debug(
                b"UTF-8 %d, wctomb() %d\0" as *const u8 as *const i8,
                wc,
                *__errno_location(),
            )
        });
        (unsafe { wctomb(std::ptr::null_mut::<i8>(), 0) });
        return UTF8_ERROR;
    }
    if size == 0 {
        return UTF8_ERROR;
    }
    (unsafe { (*ud).have = size as u_char });
    (unsafe { (*ud).size = (*ud).have });
    if utf8_width(ud, &mut width) as u32 == UTF8_DONE as i32 as u32 {
        (unsafe { (*ud).width = width as u_char });
        return UTF8_DONE;
    }
    return UTF8_ERROR;
}
#[no_mangle]
pub extern "C" fn utf8_open(mut ud: *mut utf8_data, mut ch: u_char) -> utf8_state {
    (unsafe {
        memset(
            ud as *mut (), 0,
            ::core::mem::size_of::<utf8_data>() as u64,
        )
    });
    if ch as i32 >= 0xc2 as i32 && ch as i32 <= 0xdf as i32 {
        (unsafe { (*ud).size = 2 as u_char });
    } else if ch as i32 >= 0xe0 as i32 && ch as i32 <= 0xef as i32 {
        (unsafe { (*ud).size = 3 as u_char });
    } else if ch as i32 >= 0xf0 as i32 && ch as i32 <= 0xf4 as i32 {
        (unsafe { (*ud).size = 4 as u_char });
    } else {
        return UTF8_ERROR;
    }
    utf8_append(ud, ch);
    return UTF8_MORE;
}
#[no_mangle]
pub extern "C" fn utf8_append(mut ud: *mut utf8_data, mut ch: u_char) -> utf8_state {
    let mut width: i32 = 0;
    if (unsafe { (*ud).have }) as i32 >= (unsafe { (*ud).size }) as i32 {
        (unsafe { fatalx(b"UTF-8 character overflow\0" as *const u8 as *const i8) });
    }
    if (unsafe { (*ud).size }) as u64 > ::core::mem::size_of::<[u_char; 21]>() as u64 {
        (unsafe { fatalx(b"UTF-8 character size too large\0" as *const u8 as *const i8) });
    }
    if (unsafe { (*ud).have }) as i32 != 0 && ch as i32 & 0xc0 as i32 != 0x80 as i32 {
        (unsafe { (*ud).width = 0xff as i32 as u_char });
    }
    let fresh1 = unsafe { (*ud).have };
    (unsafe { (*ud).have = ((*ud).have).wrapping_add(1) });
    (unsafe { (*ud).data[fresh1 as usize] = ch });
    if (unsafe { (*ud).have }) as i32 != (unsafe { (*ud).size }) as i32 {
        return UTF8_MORE;
    }
    if (unsafe { (*ud).width }) as i32 == 0xff as i32 {
        return UTF8_ERROR;
    }
    if utf8_width(ud, &mut width) as u32 != UTF8_DONE as i32 as u32 {
        return UTF8_ERROR;
    }
    (unsafe { (*ud).width = width as u_char });
    return UTF8_DONE;
}
#[no_mangle]
pub extern "C" fn utf8_strvis(
    mut dst: *mut i8,
    mut src: *const i8,
    mut len: size_t,
    mut flag: i32,
) -> i32 {
    let mut ud: utf8_data = utf8_data {
        data: [0; 21],
        have: 0,
        size: 0,
        width: 0,
    };
    let mut start: *const i8 = dst;
    let mut end: *const i8 = unsafe { src.offset(len as isize) };
    let mut more: utf8_state = UTF8_MORE;
    let mut i: size_t = 0;
    while src < end {
        more = utf8_open(&mut ud, (unsafe { *src }) as u_char);
        if more as u32 == UTF8_MORE as i32 as u32 {
            loop {
                src = unsafe { src.offset(1) };
                if !(src < end && more as u32 == UTF8_MORE as i32 as u32) {
                    break;
                }
                more = utf8_append(&mut ud, (unsafe { *src }) as u_char);
            }
            if more as u32 == UTF8_DONE as i32 as u32 {
                i = 0 as size_t;
                while i < ud.size as u64 {
                    let fresh2 = dst;
                    dst = unsafe { dst.offset(1) };
                    (unsafe { *fresh2 = ud.data[i as usize] as i8 });
                    i = i.wrapping_add(1);
                }
                continue;
            } else {
                src = unsafe { src.offset(-(ud.have as i32 as isize)) };
            }
        }
        if flag & 0x200 as i32 != 0
            && (unsafe { *src.offset(0 as i32 as isize) }) as i32 == '$' as i32
            && src < (unsafe { end.offset(-(1 as i32 as isize)) })
        {
            if (unsafe {
                *(*__ctype_b_loc()).offset(*src.offset(1 as i32 as isize) as u_char as i32 as isize)
            }) as i32
                & _ISalpha as i32 as u16 as i32
                != 0
                || (unsafe { *src.offset(1 as i32 as isize) }) as i32 == '_' as i32
                || (unsafe { *src.offset(1 as i32 as isize) }) as i32 == '{' as i32
            {
                let fresh3 = dst;
                dst = unsafe { dst.offset(1) };
                (unsafe { *fresh3 = '\\' as i32 as i8 });
            }
            let fresh4 = dst;
            dst = unsafe { dst.offset(1) };
            (unsafe { *fresh4 = '$' as i32 as i8 });
        } else if src < (unsafe { end.offset(-(1 as i32 as isize)) }) {
            dst = unsafe {
                vis(
                    dst,
                    *src.offset(0 as i32 as isize) as i32,
                    flag,
                    *src.offset(1 as i32 as isize) as i32,
                )
            };
        } else if src < end {
            dst = unsafe {
                vis(
                    dst,
                    *src.offset(0 as i32 as isize) as i32,
                    flag,
                    '\0' as i32,
                )
            };
        }
        src = unsafe { src.offset(1) };
    }
    (unsafe { *dst = '\0' as i32 as i8 });
    return (unsafe { dst.offset_from(start) }) as i64 as i32;
}
#[no_mangle]
pub extern "C" fn utf8_stravis(mut dst: *mut *mut i8, mut src: *const i8, mut flag: i32) -> i32 {
    let mut buf: *mut i8 = std::ptr::null_mut::<i8>();
    let mut len: i32 = 0;
    buf = (unsafe {
        xreallocarray(
            std::ptr::null_mut::<()>(), 4 as size_t,
            (strlen(src)).wrapping_add(1 as i32 as u64),
        )
    }) as *mut i8;
    len = utf8_strvis(buf, src, unsafe { strlen(src) }, flag);
    (unsafe { *dst = xrealloc(buf as *mut (), (len + 1) as size_t) as *mut i8 });
    return len;
}
#[no_mangle]
pub extern "C" fn utf8_stravisx(
    mut dst: *mut *mut i8,
    mut src: *const i8,
    mut srclen: size_t,
    mut flag: i32,
) -> i32 {
    let mut buf: *mut i8 = std::ptr::null_mut::<i8>();
    let mut len: i32 = 0;
    buf = (unsafe {
        xreallocarray(
            std::ptr::null_mut::<()>(), 4 as size_t,
            srclen.wrapping_add(1 as i32 as u64),
        )
    }) as *mut i8;
    len = utf8_strvis(buf, src, srclen, flag);
    (unsafe { *dst = xrealloc(buf as *mut (), (len + 1) as size_t) as *mut i8 });
    return len;
}
#[no_mangle]
pub extern "C" fn utf8_isvalid(mut s: *const i8) -> i32 {
    let mut ud: utf8_data = utf8_data {
        data: [0; 21],
        have: 0,
        size: 0,
        width: 0,
    };
    let mut end: *const i8 = std::ptr::null::<i8>();
    let mut more: utf8_state = UTF8_MORE;
    end = unsafe { s.offset(strlen(s) as isize) };
    while s < end {
        more = utf8_open(&mut ud, (unsafe { *s }) as u_char);
        if more as u32 == UTF8_MORE as i32 as u32 {
            loop {
                s = unsafe { s.offset(1) };
                if !(s < end && more as u32 == UTF8_MORE as i32 as u32) {
                    break;
                }
                more = utf8_append(&mut ud, (unsafe { *s }) as u_char);
            }
            if more as u32 == UTF8_DONE as i32 as u32 {
                continue;
            }
            return 0;
        } else {
            if ((unsafe { *s }) as i32) < 0x20 as i32 || (unsafe { *s }) as i32 > 0x7e as i32 {
                return 0;
            }
            s = unsafe { s.offset(1) };
        }
    }
    return 1;
}
#[no_mangle]
pub extern "C" fn utf8_sanitize(mut src: *const i8) -> *mut i8 {
    let mut dst: *mut i8 = std::ptr::null_mut::<i8>();
    let mut n: size_t = 0 as size_t;
    let mut more: utf8_state = UTF8_MORE;
    let mut ud: utf8_data = utf8_data {
        data: [0; 21],
        have: 0,
        size: 0,
        width: 0,
    };
    let mut i: u_int = 0;
    while (unsafe { *src }) as i32 != '\0' as i32 {
        dst = (unsafe {
            xreallocarray(
                dst as *mut (),
                n.wrapping_add(1 as i32 as u64),
                ::core::mem::size_of::<i8>() as u64,
            )
        }) as *mut i8;
        more = utf8_open(&mut ud, (unsafe { *src }) as u_char);
        if more as u32 == UTF8_MORE as i32 as u32 {
            loop {
                src = unsafe { src.offset(1) };
                if !((unsafe { *src }) as i32 != '\0' as i32
                    && more as u32 == UTF8_MORE as i32 as u32)
                {
                    break;
                }
                more = utf8_append(&mut ud, (unsafe { *src }) as u_char);
            }
            if more as u32 == UTF8_DONE as i32 as u32 {
                dst = (unsafe {
                    xreallocarray(
                        dst as *mut (),
                        n.wrapping_add(ud.width as u64),
                        ::core::mem::size_of::<i8>() as u64,
                    )
                }) as *mut i8;
                i = 0 as u_int;
                while i < ud.width as u32 {
                    let fresh5 = n;
                    n = n.wrapping_add(1);
                    (unsafe { *dst.offset(fresh5 as isize) = '_' as i32 as i8 });
                    i = i.wrapping_add(1);
                }
                continue;
            } else {
                src = unsafe { src.offset(-(ud.have as i32 as isize)) };
            }
        }
        if (unsafe { *src }) as i32 > 0x1f as i32 && ((unsafe { *src }) as i32) < 0x7f as i32 {
            let fresh6 = n;
            n = n.wrapping_add(1);
            (unsafe { *dst.offset(fresh6 as isize) = *src });
        } else {
            let fresh7 = n;
            n = n.wrapping_add(1);
            (unsafe { *dst.offset(fresh7 as isize) = '_' as i32 as i8 });
        }
        src = unsafe { src.offset(1) };
    }
    dst = (unsafe {
        xreallocarray(
            dst as *mut (),
            n.wrapping_add(1 as i32 as u64),
            ::core::mem::size_of::<i8>() as u64,
        )
    }) as *mut i8;
    (unsafe { *dst.offset(n as isize) = '\0' as i32 as i8 });
    return dst;
}
#[no_mangle]
pub extern "C" fn utf8_strlen(mut s: *const utf8_data) -> size_t {
    let mut i: size_t = 0;
    i = 0 as size_t;
    while (unsafe { (*s.offset(i as isize)).size }) as i32 != 0 {
        i = i.wrapping_add(1);
    }
    return i;
}
#[no_mangle]
pub extern "C" fn utf8_strwidth(mut s: *const utf8_data, mut n: ssize_t) -> u_int {
    let mut i: ssize_t = 0;
    let mut width: u_int = 0 as u_int;
    i = 0 as ssize_t;
    while (unsafe { (*s.offset(i as isize)).size }) as i32 != 0 {
        if n != -(1 as i32) as i64 && n == i {
            break;
        }
        width = (width as u32).wrapping_add((unsafe { (*s.offset(i as isize)).width }) as u32)
            as u_int as u_int;
        i += 1;
    }
    return width;
}
#[no_mangle]
pub extern "C" fn utf8_fromcstr(mut src: *const i8) -> *mut utf8_data {
    let mut dst: *mut utf8_data = std::ptr::null_mut::<utf8_data>();
    let mut n: size_t = 0 as size_t;
    let mut more: utf8_state = UTF8_MORE;
    while (unsafe { *src }) as i32 != '\0' as i32 {
        dst = (unsafe {
            xreallocarray(
                dst as *mut (),
                n.wrapping_add(1 as i32 as u64),
                ::core::mem::size_of::<utf8_data>() as u64,
            )
        }) as *mut utf8_data;
        more = utf8_open(
            unsafe { &mut *dst.offset(n as isize) },
            (unsafe { *src }) as u_char,
        );
        if more as u32 == UTF8_MORE as i32 as u32 {
            loop {
                src = unsafe { src.offset(1) };
                if !((unsafe { *src }) as i32 != '\0' as i32
                    && more as u32 == UTF8_MORE as i32 as u32)
                {
                    break;
                }
                more = utf8_append(
                    unsafe { &mut *dst.offset(n as isize) },
                    (unsafe { *src }) as u_char,
                );
            }
            if more as u32 == UTF8_DONE as i32 as u32 {
                n = n.wrapping_add(1);
                continue;
            } else {
                src = unsafe { src.offset(-((*dst.offset(n as isize)).have as i32 as isize)) };
            }
        }
        utf8_set(
            unsafe { &mut *dst.offset(n as isize) },
            (unsafe { *src }) as u_char,
        );
        n = n.wrapping_add(1);
        src = unsafe { src.offset(1) };
    }
    dst = (unsafe {
        xreallocarray(
            dst as *mut (),
            n.wrapping_add(1 as i32 as u64),
            ::core::mem::size_of::<utf8_data>() as u64,
        )
    }) as *mut utf8_data;
    (unsafe { (*dst.offset(n as isize)).size = 0 as u_char });
    return dst;
}
#[no_mangle]
pub extern "C" fn utf8_tocstr(mut src: *mut utf8_data) -> *mut i8 {
    let mut dst: *mut i8 = std::ptr::null_mut::<i8>();
    let mut n: size_t = 0 as size_t;
    while (unsafe { (*src).size }) as i32 != 0 {
        dst = (unsafe {
            xreallocarray(
                dst as *mut (),
                n.wrapping_add((*src).size as u64), 1 as size_t,
            )
        }) as *mut i8;
        (unsafe {
            memcpy(
                dst.offset(n as isize) as *mut (),
                ((*src).data).as_mut_ptr() as *const (),
                (*src).size as u64,
            )
        });
        n = (n as u64).wrapping_add((unsafe { (*src).size }) as u64) as size_t as size_t;
        src = unsafe { src.offset(1) };
    }
    dst = (unsafe {
        xreallocarray(
            dst as *mut (),
            n.wrapping_add(1 as i32 as u64), 1 as size_t,
        )
    }) as *mut i8;
    (unsafe { *dst.offset(n as isize) = '\0' as i32 as i8 });
    return dst;
}
#[no_mangle]
pub extern "C" fn utf8_cstrwidth(mut s: *const i8) -> u_int {
    let mut tmp: utf8_data = utf8_data {
        data: [0; 21],
        have: 0,
        size: 0,
        width: 0,
    };
    let mut width: u_int = 0;
    let mut more: utf8_state = UTF8_MORE;
    width = 0 as u_int;
    while (unsafe { *s }) as i32 != '\0' as i32 {
        more = utf8_open(&mut tmp, (unsafe { *s }) as u_char);
        if more as u32 == UTF8_MORE as i32 as u32 {
            loop {
                s = unsafe { s.offset(1) };
                if !((unsafe { *s }) as i32 != '\0' as i32
                    && more as u32 == UTF8_MORE as i32 as u32)
                {
                    break;
                }
                more = utf8_append(&mut tmp, (unsafe { *s }) as u_char);
            }
            if more as u32 == UTF8_DONE as i32 as u32 {
                width = (width as u32).wrapping_add(tmp.width as u32) as u_int as u_int;
                continue;
            } else {
                s = unsafe { s.offset(-(tmp.have as i32 as isize)) };
            }
        }
        if (unsafe { *s }) as i32 > 0x1f as i32 && (unsafe { *s }) as i32 != 0x7f as i32 {
            width = width.wrapping_add(1);
        }
        s = unsafe { s.offset(1) };
    }
    return width;
}
#[no_mangle]
pub extern "C" fn utf8_padcstr(mut s: *const i8, mut width: u_int) -> *mut i8 {
    let mut slen: size_t = 0;
    let mut out: *mut i8 = std::ptr::null_mut::<i8>();
    let mut n: u_int = 0;
    let mut i: u_int = 0;
    n = utf8_cstrwidth(s);
    if n >= width {
        return unsafe { xstrdup(s) };
    }
    slen = unsafe { strlen(s) };
    out = (unsafe {
        xmalloc(
            slen.wrapping_add(1 as i32 as u64)
                .wrapping_add(width.wrapping_sub(n) as u64),
        )
    }) as *mut i8;
    (unsafe { memcpy(out as *mut (), s as *const (), slen) });
    i = n;
    while i < width {
        let fresh8 = slen;
        slen = slen.wrapping_add(1);
        (unsafe { *out.offset(fresh8 as isize) = ' ' as i32 as i8 });
        i = i.wrapping_add(1);
    }
    (unsafe { *out.offset(slen as isize) = '\0' as i32 as i8 });
    return out;
}
#[no_mangle]
pub extern "C" fn utf8_rpadcstr(mut s: *const i8, mut width: u_int) -> *mut i8 {
    let mut slen: size_t = 0;
    let mut out: *mut i8 = std::ptr::null_mut::<i8>();
    let mut n: u_int = 0;
    let mut i: u_int = 0;
    n = utf8_cstrwidth(s);
    if n >= width {
        return unsafe { xstrdup(s) };
    }
    slen = unsafe { strlen(s) };
    out = (unsafe {
        xmalloc(
            slen.wrapping_add(1 as i32 as u64)
                .wrapping_add(width.wrapping_sub(n) as u64),
        )
    }) as *mut i8;
    i = 0 as u_int;
    while i < width.wrapping_sub(n) {
        (unsafe { *out.offset(i as isize) = ' ' as i32 as i8 });
        i = i.wrapping_add(1);
    }
    (unsafe {
        memcpy(
            out.offset(i as isize) as *mut (),
            s as *const (),
            slen,
        )
    });
    (unsafe { *out.offset((i as u64).wrapping_add(slen) as isize) = '\0' as i32 as i8 });
    return out;
}
#[no_mangle]
pub extern "C" fn utf8_cstrhas(mut s: *const i8, mut ud: *const utf8_data) -> i32 {
    let mut copy: *mut utf8_data = std::ptr::null_mut::<utf8_data>();
    let mut loop_0: *mut utf8_data = std::ptr::null_mut::<utf8_data>();
    let mut found: i32 = 0;
    copy = utf8_fromcstr(s);
    loop_0 = copy;
    while (unsafe { (*loop_0).size }) as i32 != 0 {
        if (unsafe { (*loop_0).size }) as i32 == (unsafe { (*ud).size }) as i32 {
            if (unsafe {
                memcmp(
                    ((*loop_0).data).as_mut_ptr() as *const (),
                    ((*ud).data).as_ptr() as *const (),
                    (*loop_0).size as u64,
                )
            }) == 0
            {
                found = 1;
                break;
            }
        }
        loop_0 = unsafe { loop_0.offset(1) };
    }
    (unsafe { free(copy as *mut ()) });
    return found;
}
